package com.yuanqi.repository;

import com.yuanqi.domain.Payment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface PaymentRepository extends JpaRepository<Payment, Long> {
    
    List<Payment> findBySupplierId(Long supplierId);
    
    List<Payment> findByPaymentDateBetween(LocalDate startDate, LocalDate endDate);
    
    @Query("SELECT SUM(p.amount) FROM Payment p WHERE p.paymentDate BETWEEN ?1 AND ?2")
    Double getTotalPaymentAmount(LocalDate startDate, LocalDate endDate);
    
    boolean existsByPaymentCode(String paymentCode);
}


